package com.itheima.config;

import com.itheima.interc.LoginCheck;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
        addResourceHandler：添加URL响应地址目录。
        addResourceLocations：添加实际资源目录。
        */
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //将拦截器添加到Springmvc环境,默认拦截所有Springmvc分发的请求
        //也支持 /* 和 /** 模糊路径。 * 任意一层字符串 ** 任意层 任意字符串
        registry.addInterceptor(new LoginCheck()).addPathPatterns("/**").
                excludePathPatterns("/employee/login",
                        "/employee/logout",
                        "/backend/**",
                        "/front/**",
                        "/common/**",
                        "/user/sendMsg",
                        "/user/login");
                                                                     //那现在拦截了些什么呢?
    }
}
